package com.guigu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.base.entity.GoodsType;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.base.entity.TruckType;
import com.guigu.base.entity.TruckTypeGoodsType;
import com.guigu.base.entity.vo.GoodsTypeVo;
import com.guigu.base.mapper.GoodsTypeMapper;
import com.guigu.base.service.GoodsTypeService;
import com.guigu.base.service.TruckTypeGoodsTypeService;
import com.guigu.base.service.TruckTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 货物类型表 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-08
 */
@Service
public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeMapper, GoodsType> implements GoodsTypeService {

    /**
     * 保存货物类型
     * @param GoodsType
     * @return
     */
    @Override
    public GoodsType saveGoodsType(GoodsType GoodsType) {
        baseMapper.insert(GoodsType);
        return GoodsType;
    }

    /**
     * 查询所有货物类型
     * @return
     */
    @Override
    public List<GoodsType> findAll() {
        QueryWrapper<GoodsType> queryWrapper = new QueryWrapper<>();
        //添加条件，根据status查询
        queryWrapper.eq("status",1);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 分页查询货物类型
     * @param page
     * @param pageSize
     * @param name
     * @param truckTypeId
     * @param truckTypeName
     * @return
     */
    @Override
    public IPage<GoodsType> findByPage(Integer page, Integer pageSize, String name, String truckTypeId, String truckTypeName) {
        //封装分页条件
        Page<GoodsType> pdPage = new Page<>(page,pageSize);
        //排序条件
        pdPage.setRecords(baseMapper.findByPage(pdPage,name,truckTypeId,truckTypeName));
        return pdPage;
    }

    /**
     * 查询货物类型列表
     * @param ids
     * @return
     */
    @Override
    public List<GoodsType> findAll(List<String> ids) {
        LambdaQueryWrapper<GoodsType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(ids != null && ids.size() > 0){
            //添加查询条件
            lambdaQueryWrapper.in(GoodsType::getId,ids);
        }
        return baseMapper.selectList(lambdaQueryWrapper);
    }

}
